package dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import dto.AddressDTO;
import dto.FileListDTO;
import dto.MemberDTO;
import dto.PrivacyDTO;
import dto.PropertyDTO;
import dto.RefundDTO;
import dto.RoomDTO;
import dto.RoomDTO2;

public class RoomDAO {
	private SqlMapClientTemplate sqlMap;
	public RoomDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	public void insertRoom(RoomDTO rdto)  throws SQLException{
		sqlMap.insert("insertRoom", rdto);
	}
	public int selectRoomNo() throws SQLException{
		return (Integer)sqlMap.queryForObject("roomNumberGen");
	}
	public int selectFileNo() throws SQLException{
		return (Integer)sqlMap.queryForObject("fileNumberGen");
	}
	public void insertFile(FileListDTO fdto)  throws SQLException{
		sqlMap.insert("insertFile", fdto);
	}
	public ArrayList<AddressDTO> searchAddress(String dong) {
		return (ArrayList<AddressDTO>) sqlMap.queryForList("searchAddress",dong);
	}
	public PropertyDTO selectPropertyId(String propertyId) throws SQLException{
		return (PropertyDTO)sqlMap.queryForObject("selectPropertyId", propertyId);
	}
	public PrivacyDTO selectPrivacyId(String privacyId) throws SQLException{
		return (PrivacyDTO)sqlMap.queryForObject("selectPrivacyId", privacyId);
	}
	public RefundDTO selectRefundId(String refundId) throws SQLException{
		return (RefundDTO)sqlMap.queryForObject("selectRefundId", refundId);
	}
	public AddressDTO selectAddress(String addressId) throws SQLException{
		return (AddressDTO)sqlMap.queryForObject("searchBySeq", addressId);
	}
	public void removeRoom(int roomNo) throws SQLException{
		sqlMap.delete("removeRoom", roomNo);
	}
	public ArrayList<FileListDTO> selectFileListByRoomNo(int roomNo) throws SQLException{
		return (ArrayList<FileListDTO>)sqlMap.queryForList("selectFileListByRoomNo", roomNo);
	}
	public RoomDTO selectByRoomNo(int roomNo) throws SQLException{
		return (RoomDTO)sqlMap.queryForObject("selectByRoomNo", roomNo);
	}
	public ArrayList<RoomDTO> selectByMemberId(String memberId) throws SQLException{
		return (ArrayList<RoomDTO>)sqlMap.queryForList("selectByMemberId", memberId);
	}
	
	public ArrayList<RoomDTO> selectMyRoomListByMemberId(String memberId) throws SQLException{
		return (ArrayList<RoomDTO>)sqlMap.queryForList("selectMyRoomListByMemberId", memberId);
	}
	public FileListDTO selectRoomFileByRoomNo(int roomNo) throws SQLException{
		return (FileListDTO)sqlMap.queryForObject("selectMainFile", roomNo);
	}
	public RoomDTO selectRoomDetailByRoomNo(int roomNo) throws SQLException{
		return (RoomDTO)sqlMap.queryForObject("selectRoomDetailByRoomNo", roomNo);
	}
	public void updateRoomInfoBasic(RoomDTO rdto) throws SQLException{
		sqlMap.update("updateRoomInfoBasic", rdto);
	}
	public void updateRoomInfoAdd(RoomDTO rdto) throws SQLException{
		sqlMap.update("updateRoomInfoAdd", rdto);		
	}
	public ArrayList<RoomDTO2> allRoomList2() {
		System.out.println("dao쪽입니다.");
		return (ArrayList<RoomDTO2>) sqlMap.queryForList("allRoomList2");
	}
	public ArrayList allFileList() {
		return (ArrayList)sqlMap.queryForList("allFileList");
	}
	public ArrayList allPrivacyList() {
		return (ArrayList)sqlMap.queryForList("allPrivacyList");
	}
	public ArrayList<RoomDTO> selectByDong(String dong) {
		return (ArrayList<RoomDTO>) sqlMap.queryForList("selectByDong",dong);
	}
	public ArrayList<RoomDTO2> selectByadmin(String id) {
		return (ArrayList<RoomDTO2>) sqlMap.queryForList("selectByadmin",id);
	}
	public void deleteFile(String filename) {
		sqlMap.delete("deleteFile",filename);
		
	}
	public String randomImage() {
		return (String)sqlMap.queryForObject("randomImage");
		
		
	}
	public ArrayList<RoomDTO> selectByCity(String dong) {
		return (ArrayList<RoomDTO>) sqlMap.queryForList("selectByCity",dong);
	}
	public ArrayList<RoomDTO> selectBygugun(String dong) {
		return (ArrayList<RoomDTO>) sqlMap.queryForList("selectBygugun",dong);
	}
	public int delete(int roomNo) {
		return sqlMap.delete("deletePostScript",roomNo);
		
	}
	public String countmember() {
		return (String) sqlMap.queryForObject("countmember");
	}
	public String countroom() {
		return (String)sqlMap.queryForObject("countroom");
	}
}
